import 'package:flutter/material.dart';
import 'package:homepad/iot/basic_types.dart';
import 'package:homepad/iot/humidity_sensor.dart';
import 'package:homepad/iot/temperature_sensor.dart';
import 'package:homepad/models/nova_model.dart';
import 'package:homepad/styles.dart';
import 'package:provider/provider.dart';

class RoomSensorWidget extends StatelessWidget {
  const RoomSensorWidget({super.key});

  @override
  Widget build(BuildContext context) {
    var temperature = context.select<NovaModel, String>((nova) {
      var sensor =
          nova.config.getNodeByRoomAndDevType(nova.config.location, DeviceType.temperatureSensor)
              as TemperatureSensor?;
      return "${sensor?.temperature ?? "--.-"}";
    });
    var humidity = context.select<NovaModel, String>((nova) {
      var sensor =
          nova.config.getNodeByRoomAndDevType(nova.config.location, DeviceType.humiditySensor)
              as HumiditySensor?;
      return "${sensor?.humidity ?? "--"}";
    });

    final MyStyles styles = Theme.of(context).extension<MyStyles>()!;
    final textStyle = styles.homeWeatherTemperatureTextStyle.copyWith(
      letterSpacing: 1,
      fontSize: 22,
      shadows: [
        const Shadow(
          blurRadius: 4.0,
          color: Color.fromARGB(50, 0, 0, 0),
          offset: Offset(1.0, 2.0),
        )
      ],
    );

    return SizedBox(
      height: 50,
      width: 250,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          const Image(
              width: 50, height: 50, image: AssetImage("assets/images/icon_font_temperature.png")),
          Container(
              padding: const EdgeInsets.only(left: 5),
              width: 70,
              child: Text("$temperature°", style: textStyle)),
          const SizedBox(width: 10),
          const Image(
              width: 50, height: 50, image: AssetImage("assets/images/icon_font_humidity.png")),
          Container(
            padding: const EdgeInsets.only(left: 5),
            width: 70,
            child: Text("$humidity%", style: textStyle),
          ),
        ],
      ),
    );
  }
}
